home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / SCRNSAVE.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  2KB  |  82 lines

  1. .I 0 79
  2. /*
  3. **  SCRNSAVE.C - Save and restore text screen portably
  4. **
  5. **  public domain demo by Bob Stout
  6. */
  7.  
  8. #include <stdlib.h>
  9.  
  10. /*
  11. **  Stuff from SNIPPETS courtesy of Jim Nutt
  12. **
  13. **  Notes: VIOopen() is called redundantly to assure that the video
  14. **         information is always initialized. These multiple calls are benign.
  15. **
  16. **         Because of using VIO.OBJ, this *must* be compiled in large model!
  17. */
  18.  
  19. #include "vio.h"
  20.  
  21. /*
  22. **  Save the current text screen
  23. **
  24. **  Arguments: None
  25. **
  26. **  Returns: Pointer to saved screen buffer, NULL if insufficient heap
  27. */
  28.  
  29. unsigned short *savescreen(void)
  30. {
  31.       unsigned short *vbuf;
  32.  
  33.       VIOopen();
  34.       if (NULL == (vbuf = malloc(VIOcolumns() * VIOrows() * 2)))
  35.             return NULL;
  36.       VIOgetra(0, 0, VIOcolumns() - 1, VIOrows() - 1, (int _far *)vbuf);
  37.       return vbuf;
  38. }
  39.  
  40. /*
  41. **  Restore a screen previously saved by savescreen()
  42. **
  43. **  Arguments: Buffer containing the screen to restore
  44. **
  45. **  Returns: Nothing
  46. **
  47. **  WARNING: No error checking done to verify same screen size and mode!
  48. */
  49.  
  50. void restorescreen(unsigned short *vbuf)
  51. {
  52.       VIOopen();
  53.       VIOputr(0, 0, VIOcolumns(), VIOrows(), (int _far *)vbuf);
  54.       free(vbuf);
  55. }
  56.  
  57. #ifdef TEST
  58.  
  59. #include <stdio.h>
  60. #include <conio.h>
  61.  
  62. int main(void)
  63. {
  64.       unsigned short *vbuf;
  65.  
  66.       VIOopen();
  67.       if (NULL == (vbuf = savescreen()))
  68.       {
  69.             puts("Unable to save screen");
  70.             return EXIT_FAILURE;
  71.       }
  72.       VIOclear(0, 0, VIOcolumns(), VIOrows());
  73.       puts("Hit any key to exit");
  74.       getch();
  75.       restorescreen(vbuf);
  76.       VIOclose();
  77.       return EXIT_SUCCESS;
  78. }
  79.  
  80. #endif /* TEST */
  81. .D 1 86
  82.